package mysql

import (
	"e_mall_server/models"
)

/**
 * @Author: zhaobin
 * @Description TODO
 * @Date: 2022-05-07 14:42
 */

// DeleteAccessByRoleId 通过角色id删除权限数据
func DeleteAccessByRoleId(id int64) error {
	return db.Debug().Where("role_id = ?", id).Delete(&models.RoleAccess{}).Error
}

// AddAccessToRole 给角色授权,增加某角色对应的权限
func AddAccessToRole(roleId int64, accessIds []int64) error {

	roleAccess := models.RoleAccess{RoleId: roleId}
	for _, v := range accessIds {
		roleAccess.AccessId = v
		// 增加某角色对应的权限
		if err := db.Create(&roleAccess).Error; err != nil {
			return err
		}
	}
	return nil
}
